package xyz.ymtao.service;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import xyz.ymtao.event.BlockedListEvent;

import java.util.List;

/**
 * @author: ymt
 * @description:
 * @date: 2021/8/19  10:56
 */
@Service
public class EmailService implements ApplicationEventPublisherAware {

    private List<String> blockedList;
    private ApplicationEventPublisher publisher;

    public void setBlockedList(List<String> blockedList) {
        this.blockedList = blockedList;
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }

    public void sendEmail(String address,String content){
        if(blockedList.contains(address)){
            publisher.publishEvent(new BlockedListEvent(this,address,content));
            return;
        }
        System.out.println("send email==============>" + content);
    }
}
